
## Replication file for Isabela Mares and Alexander Trubowitz, "Electoral Rules, Programmatic Competition, and Redistribution: Evidence from Interwar France"

required_packages <- c("readxl","here","plm","lmtest","fixest","stargazer","dplyr","ggplot2")

# Install missing packages
installed <- rownames(installed.packages())

for (pkg in required_packages) {
  if (!(pkg %in% installed)) {
    install.packages(pkg, dependencies = TRUE)
  }
}

# Load packages
invisible(lapply(required_packages, library, character.only = TRUE))


# Download the the three data sets. The excel files are cps_bills.xlsx, cps_bills1902_1932.xlsx, and cps_platforms.xlsx

bills <- read_excel(here("cps_bills.xlsx"))
bills_extended <- read_excel(here("cps_bills1902_1932.xlsx"))
platforms <- read_excel(here("cps_platforms.xlsx"))


# Set 1: analysis of bill proposals with binary PR variable. Full sample (1914-1932). First row of coefficients in Figure 3 of the main text; Appendix Table D1.


plm_fit1.1 <- plm(socialpolicybills ~ pr, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit1.1 <- coeftest(plm_fit1.1, vcov = plm::vcovHC(plm_fit1.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.1_coef <- coeftest_plm_fit1.1[,c(1)] 
plm_fit1.1_se <- coeftest_plm_fit1.1[,2] 

plm_fit1.2 <- plm(labormarketbills ~ pr, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit1.2 <- coeftest(plm_fit1.2, vcov = plm::vcovHC(plm_fit1.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.2_coef <- coeftest_plm_fit1.2[,c(1)] 
plm_fit1.2_se <- coeftest_plm_fit1.2[,2] 

plm_fit1.3 <- plm(taxationbills ~ pr, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit1.3 <- coeftest(plm_fit1.3, vcov = plm::vcovHC(plm_fit1.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.3_coef <- coeftest_plm_fit1.3[,c(1)] 
plm_fit1.3_se <- coeftest_plm_fit1.3[,2] 

plm_fit1.4 <- plm(pork ~ pr, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit1.4 <- coeftest(plm_fit1.4, vcov = plm::vcovHC(plm_fit1.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.4_coef <- coeftest_plm_fit1.4[,c(1)] 
plm_fit1.4_se <- coeftest_plm_fit1.4[,2] 

stargazer(plm_fit1.1, plm_fit1.2, plm_fit1.3, plm_fit1.4, 
          coef = list(plm_fit1.1_coef, plm_fit1.2_coef, plm_fit1.3_coef, plm_fit1.4_coef),
          se = list(plm_fit1.1_se, plm_fit1.2_se, plm_fit1.3_se,plm_fit1.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## same analyses with full set of control variables. Second row of coefficients in Figure 3 of the main text; Appendix Table D3.

plm_fit1.5 <- plm(socialpolicybills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit1.5 <- coeftest(plm_fit1.5, vcov = plm::vcovHC(plm_fit1.5, method = "arellano", type = "HC1", cluster = "group")) 
plm_fit1.5_coef <- coeftest_plm_fit1.5[,c(1)] 
plm_fit1.5_se <- coeftest_plm_fit1.5[,2] 

plm_fit1.6 <- plm(labormarketbills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit1.6 <- coeftest(plm_fit1.6, vcov = plm::vcovHC(plm_fit1.6, method = "arellano", type = "HC1", cluster = "group")) 
plm_fit1.6_coef <- coeftest_plm_fit1.6[,c(1)] 
plm_fit1.6_se <- coeftest_plm_fit1.6[,2] 

plm_fit1.7 <- plm(taxationbills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit1.7 <- coeftest(plm_fit1.7, vcov = plm::vcovHC(plm_fit1.7, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.7_coef <- coeftest_plm_fit1.7[,c(1)] 
plm_fit1.7_se <- coeftest_plm_fit1.7[,2] 

plm_fit1.8 <- plm(pork ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit1.8 <- coeftest(plm_fit1.8, vcov = plm::vcovHC(plm_fit1.8, method = "arellano", type = "HC1", cluster = "group"))
plm_fit1.8_coef <- coeftest_plm_fit1.8[,c(1)]
plm_fit1.8_se <- coeftest_plm_fit1.8[,2] 

stargazer(plm_fit1.5, plm_fit1.6, plm_fit1.7, plm_fit1.8, 
          coef = list(plm_fit1.5_coef, plm_fit1.6_coef, plm_fit1.7_coef, plm_fit1.8_coef),
          se = list(plm_fit1.5_se, plm_fit1.6_se, plm_fit1.7_se,plm_fit1.8_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## Count models (Appendix O)

poisson_fit1.1 <- fepois(socialpolicybills ~ pr, bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm='none') 
etable(poisson_fit1.1)

poisson_fit1.2 <- fepois(labormarketbills ~ pr, bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm='none') 
etable(poisson_fit1.2)

poisson_fit1.3 <- fepois(taxationbills ~ pr, bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm='none') 
etable(poisson_fit1.3)

poisson_fit1.4 <- fepois(pork ~ pr, bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm='none') 
etable(poisson_fit1.4)


# Set 2: analysis of bill proposals with binary PR variable. Postwar sample (1919-1932). Third row of coefficients in Figure 3 of the main text; Appendix Table D2. 

bills_pw <- subset(bills, legislativeperiod %in% c(12,13,14))

plm_fit2.1 <- plm(socialpolicybills ~ pr, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit2.1 <- coeftest(plm_fit2.1, vcov = plm::vcovHC(plm_fit2.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.1_coef <- coeftest_plm_fit2.1[,c(1)] 
plm_fit2.1_se <- coeftest_plm_fit2.1[,2] 

plm_fit2.2 <- plm(labormarketbills ~ pr, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit2.2 <- coeftest(plm_fit2.2, vcov = plm::vcovHC(plm_fit2.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.2_coef <- coeftest_plm_fit2.2[,c(1)]
plm_fit2.2_se <- coeftest_plm_fit2.2[,2] 

plm_fit2.3 <- plm(taxationbills ~ pr, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit2.3 <- coeftest(plm_fit2.3, vcov = plm::vcovHC(plm_fit2.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.3_coef <- coeftest_plm_fit2.3[,c(1)] 
plm_fit2.3_se <- coeftest_plm_fit2.3[,2] 

plm_fit2.4 <- plm(pork ~ pr, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit2.4 <- coeftest(plm_fit2.4, vcov = plm::vcovHC(plm_fit2.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.4_coef <- coeftest_plm_fit2.4[,c(1)] 
plm_fit2.4_se <- coeftest_plm_fit2.4[,2] 

stargazer(plm_fit2.1, plm_fit2.2, plm_fit2.3, plm_fit2.4,
          coef = list(plm_fit2.1_coef, plm_fit2.2_coef, plm_fit2.3_coef, plm_fit2.4_coef),
          se = list(plm_fit2.1_se, plm_fit2.2_se, plm_fit2.3_se,plm_fit2.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))

# version with full set of controls. Fourth row of coefficients in Figure 3 of the main text; Appendix Table D4.

plm_fit2.1c <- plm(socialpolicybills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit2.1c <- coeftest(plm_fit2.1c, vcov = plm::vcovHC(plm_fit2.1c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.1c_coef <- coeftest_plm_fit2.1c[,c(1)] 
plm_fit2.1c_se <- coeftest_plm_fit2.1c[,2]

plm_fit2.2c <- plm(labormarketbills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit2.2c <- coeftest(plm_fit2.2c, vcov = plm::vcovHC(plm_fit2.2c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.2c_coef <- coeftest_plm_fit2.2c[,c(1)] 
plm_fit2.2c_se <- coeftest_plm_fit2.2c[,2] 

plm_fit2.3c <- plm(taxationbills ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit2.3c <- coeftest(plm_fit2.3c, vcov = plm::vcovHC(plm_fit2.3c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.3c_coef <- coeftest_plm_fit2.3c[,c(1)] 
plm_fit2.3c_se <- coeftest_plm_fit2.3c[,2] 

plm_fit2.4c <- plm(pork ~ pr + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit2.4c <- coeftest(plm_fit2.4c, vcov = plm::vcovHC(plm_fit2.4c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.4c_coef <- coeftest_plm_fit2.4c[,c(1)] 
plm_fit2.4c_se <- coeftest_plm_fit2.4c[,2] 

stargazer(plm_fit2.1c, plm_fit2.2c, plm_fit2.3c, plm_fit2.4c,
          coef = list(plm_fit2.1c_coef, plm_fit2.2c_coef, plm_fit2.3c_coef, plm_fit2.4c_coef),
          se = list(plm_fit2.1c_se, plm_fit2.2c_se, plm_fit2.3c_se,plm_fit2.4c_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# test if newly elected legislators under SMD differ from re-elected legislators with interaction term (Appendix J)

bills_pw$smd <- ifelse(bills_pw$pr ==0, 1, 0)

bills_pw$reelected1928 <- ifelse(bills_pw$legislativeperiod == 14 & bills_pw$new1928 == 0, 1, 0)

table(bills_pw$legislativeperiod, bills_pw$new1928)

plm_fit2.5 <- plm(socialpolicybills ~ smd*new + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.5 <- coeftest(plm_fit2.5, vcov = plm::vcovHC(plm_fit2.5, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.5_coef <- coeftest_plm_fit2.5[,c(1)]
plm_fit2.5_se <- coeftest_plm_fit2.5[,2] 

plm_fit2.6 <- plm(labormarketbills ~ smd*new + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.6 <- coeftest(plm_fit2.6, vcov = plm::vcovHC(plm_fit2.6, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.6_coef <- coeftest_plm_fit2.6[,c(1)] 
plm_fit2.6_se <- coeftest_plm_fit2.6[,2] 

plm_fit2.7 <- plm(taxationbills ~ smd*new + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.7 <- coeftest(plm_fit2.7, vcov = plm::vcovHC(plm_fit2.7, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.7_coef <- coeftest_plm_fit2.7[,c(1)] 
plm_fit2.7_se <- coeftest_plm_fit2.7[,2] 

plm_fit2.8 <- plm(pork ~ smd*new + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.8 <- coeftest(plm_fit2.8, vcov = plm::vcovHC(plm_fit2.8, method = "arellano", type = "HC1", cluster = "group"))
plm_fit2.8_coef <- coeftest_plm_fit2.8[,c(1)] 
plm_fit2.8_se <- coeftest_plm_fit2.8[,2] 

stargazer(plm_fit2.5, plm_fit2.6, plm_fit2.7, plm_fit2.8,
          coef = list(plm_fit2.5_coef, plm_fit2.6_coef, plm_fit2.7_coef, plm_fit2.8_coef),
          se = list(plm_fit2.5_se, plm_fit2.6_se, plm_fit2.7_se,plm_fit2.8_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))

# second method: comparing new and re-elected legislators in the 14th LP (1928-1932) (Appendix K)

bills14 <- subset(bills, legislativeperiod ==14)

plm_fit2.9 <- plm(socialpolicybills ~ new1928 + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills14, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.9 <- coeftest(plm_fit2.9, vcov = plm::vcovHC(plm_fit2.9, method = "arellano", type = "HC1"))
plm_fit2.9_coef <- coeftest_plm_fit2.9[,c(1)] 
plm_fit2.9_se <- coeftest_plm_fit2.9[,2] 

plm_fit2.10 <- plm(labormarketbills ~ new1928 + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills14, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.10 <- coeftest(plm_fit2.10, vcov = plm::vcovHC(plm_fit2.10, method = "arellano", type = "HC1"))
plm_fit2.10_coef <- coeftest_plm_fit2.10[,c(1)] 
plm_fit2.10_se <- coeftest_plm_fit2.10[,2] 

plm_fit2.11 <- plm(taxationbills ~ new1928 + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills14, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.11 <- coeftest(plm_fit2.11, vcov = plm::vcovHC(plm_fit2.11, method = "arellano", type = "HC1"))
plm_fit2.11_coef <- coeftest_plm_fit2.11[,c(1)] 
plm_fit2.11_se <- coeftest_plm_fit2.11[,2] 

plm_fit2.12 <- plm(pork  ~ new1928 + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills14, index = c("legislatorid","legislativeperiod"), model = "pooling")
coeftest_plm_fit2.12 <- coeftest(plm_fit2.12, vcov = plm::vcovHC(plm_fit2.12, method = "arellano", type = "HC1"))
plm_fit2.12_coef <- coeftest_plm_fit2.12[,c(1)] 
plm_fit2.12_se <- coeftest_plm_fit2.12[,2] 

stargazer(plm_fit2.9, plm_fit2.10, plm_fit2.11, plm_fit2.12,
          coef = list(plm_fit2.9_coef, plm_fit2.10_coef, plm_fit2.11_coef, plm_fit2.12_coef),
          se = list(plm_fit2.9_se, plm_fit2.10_se, plm_fit2.11_se,plm_fit2.12_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# Set 3: analysis of bill proposals with District Magnitude variable. Full sample (1914-1932).(Table 1 in the main text)


plm_fit3.1 <- plm(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2), data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit3.1 <- coeftest(plm_fit3.1, vcov = plm::vcovHC(plm_fit3.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.1_coef <- coeftest_plm_fit3.1[,c(1)] 
plm_fit3.1_se <- coeftest_plm_fit3.1[,2] 

plm_fit3.2 <- plm(labormarketbills ~ districtmagnitude + I(districtmagnitude^2) , data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit3.2 <- coeftest(plm_fit3.2, vcov = plm::vcovHC(plm_fit3.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.2_coef <- coeftest_plm_fit3.2[,c(1)] 
plm_fit3.2_se <- coeftest_plm_fit3.2[,2] 

plm_fit3.3 <- plm(taxationbills ~ districtmagnitude + I(districtmagnitude^2), data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit3.3 <- coeftest(plm_fit3.3, vcov = plm::vcovHC(plm_fit3.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.3_coef <- coeftest_plm_fit3.3[,c(1)] 
plm_fit3.3_se <- coeftest_plm_fit3.3[,2]

plm_fit3.4 <- plm(pork ~ districtmagnitude + I(districtmagnitude^2) , data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit3.4 <- coeftest(plm_fit3.4, vcov = plm::vcovHC(plm_fit3.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.4_coef <- coeftest_plm_fit3.4[,c(1)]
plm_fit3.4_se <- coeftest_plm_fit3.4[,2] 

stargazer(plm_fit3.1, plm_fit3.2, plm_fit3.3, plm_fit3.4,
          coef = list(plm_fit3.1_coef, plm_fit3.2_coef, plm_fit3.3_coef, plm_fit3.4_coef),
          se = list(plm_fit3.1_se, plm_fit3.2_se, plm_fit3.3_se,plm_fit3.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# version with full set of controls (Appendix table E1)

plm_fit3.1c <- plm(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit3.1c <- coeftest(plm_fit3.1c, vcov = plm::vcovHC(plm_fit3.1c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.1c_coef <- coeftest_plm_fit3.1c[,c(1)] 
plm_fit3.1c_se <- coeftest_plm_fit3.1c[,2] 

plm_fit3.2c <- plm(labormarketbills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit3.2c <- coeftest(plm_fit3.2c, vcov = plm::vcovHC(plm_fit3.2c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.2c_coef <- coeftest_plm_fit3.2c[,c(1)] 
plm_fit3.2c_se <- coeftest_plm_fit3.2c[,2] 

plm_fit3.3c <- plm(taxationbills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit3.3c <- coeftest(plm_fit3.3c, vcov = plm::vcovHC(plm_fit3.3c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.3c_coef <- coeftest_plm_fit3.3c[,c(1)] 
plm_fit3.3c_se <- coeftest_plm_fit3.3c[,2] 

plm_fit3.4c <- plm(pork ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit3.4c <- coeftest(plm_fit3.4c, vcov = plm::vcovHC(plm_fit3.4c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit3.4c_coef <- coeftest_plm_fit3.4c[,c(1)] 
plm_fit3.4c_se <- coeftest_plm_fit3.4c[,2] 

stargazer(plm_fit3.1c, plm_fit3.2c, plm_fit3.3c, plm_fit3.4c,
          coef = list(plm_fit3.1c_coef, plm_fit3.2c_coef, plm_fit3.3c_coef, plm_fit3.4c_coef),
          se = list(plm_fit3.1c_se, plm_fit3.2c_se, plm_fit3.3c_se,plm_fit3.4c_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# count model (Appendix Table O2)

poisson_fit3.1 <- fepois(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2), bills, fixef = "legislatorid", cluster = "legislatorid", fixef.rm = 'none') 
etable(poisson_fit3.1)

poisson_fit3.2 <- fepois(labormarketbills ~ districtmagnitude + I(districtmagnitude^2), bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm = 'none') 
etable(poisson_fit3.2)

poisson_fit3.3 <- fepois(taxationbills ~ districtmagnitude + I(districtmagnitude^2), bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm = 'none') 
etable(poisson_fit3.3)

poisson_fit3.4 <- fepois(pork ~ districtmagnitude + I(districtmagnitude^2), bills, fixef = "legislatorid", cluster = "legislatorid",fixef.rm = 'none') 
etable(poisson_fit3.4)


# Set 4 analysis of bill proposals with District Magnitude variable. Postwar sample (1919-1932). Appendix Table E2.

plm_fit4.1 <- plm(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2), data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit4.1 <- coeftest(plm_fit4.1, vcov = plm::vcovHC(plm_fit4.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.1_coef <- coeftest_plm_fit4.1[,c(1)] 
plm_fit4.1_se <- coeftest_plm_fit4.1[,2] 

plm_fit4.2 <- plm(labormarketbills ~ districtmagnitude + I(districtmagnitude^2), data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit4.2 <- coeftest(plm_fit4.2, vcov = plm::vcovHC(plm_fit4.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.2_coef <- coeftest_plm_fit4.2[,c(1)] 
plm_fit4.2_se <- coeftest_plm_fit4.2[,2] 

plm_fit4.3 <- plm(taxationbills ~ districtmagnitude + I(districtmagnitude^2), data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit4.3 <- coeftest(plm_fit4.3, vcov = plm::vcovHC(plm_fit4.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.3_coef <- coeftest_plm_fit4.3[,c(1)] 
plm_fit4.3_se <- coeftest_plm_fit4.3[,2] 

plm_fit4.4 <- plm(pork ~ districtmagnitude + I(districtmagnitude^2), data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit4.4 <- coeftest(plm_fit4.4, vcov = plm::vcovHC(plm_fit4.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.4_coef <- coeftest_plm_fit4.4[,c(1)] 
plm_fit4.4_se <- coeftest_plm_fit4.4[,2] 

stargazer(plm_fit4.1, plm_fit4.2, plm_fit4.3, plm_fit4.4,
          coef = list(plm_fit4.1_coef, plm_fit4.2_coef, plm_fit4.3_coef, plm_fit4.4_coef),
          se = list(plm_fit4.1_se, plm_fit4.2_se, plm_fit4.3_se, plm_fit4.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## Version with controls (Appendix Table E3)

plm_fit4.1c <- plm(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit4.1c <- coeftest(plm_fit4.1c, vcov = plm::vcovHC(plm_fit4.1c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.1c_coef <- coeftest_plm_fit4.1c[,c(1)] 
plm_fit4.1c_se <- coeftest_plm_fit4.1c[,2] 

plm_fit4.2c <- plm(labormarketbills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit4.2c <- coeftest(plm_fit4.2c, vcov = plm::vcovHC(plm_fit4.2c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.2c_coef <- coeftest_plm_fit4.2c[,c(1)] 
plm_fit4.2c_se <- coeftest_plm_fit4.2c[,2] 

plm_fit4.3c <- plm(taxationbills ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit4.3c <- coeftest(plm_fit4.3c, vcov = plm::vcovHC(plm_fit4.3c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.3c_coef <- coeftest_plm_fit4.3c[,c(1)] 
plm_fit4.3c_se <- coeftest_plm_fit4.3c[,2] 

plm_fit4.4c <- plm(pork ~ districtmagnitude + I(districtmagnitude^2) + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = bills_pw, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit4.4c <- coeftest(plm_fit4.4c, vcov = plm::vcovHC(plm_fit4.4c, method = "arellano", type = "HC1", cluster = "group"))
plm_fit4.4c_coef <- coeftest_plm_fit4.4c[,c(1)] 
plm_fit4.4c_se <- coeftest_plm_fit4.4c[,2] 

stargazer(plm_fit4.1c, plm_fit4.2c, plm_fit4.3c, plm_fit4.4c,
          coef = list(plm_fit4.1c_coef, plm_fit4.2c_coef, plm_fit4.3c_coef, plm_fit4.4c_coef),
          se = list(plm_fit4.1c_se, plm_fit4.2c_se, plm_fit4.3c_se, plm_fit4.4c_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# Set 5: analysis with extended number of sessions (1902-1932) (Appendix I)

plm_fit5.1 <- plm(socialpolicybills ~  pr, data = bills_extended, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.1 <- coeftest(plm_fit5.1, vcov = plm::vcovHC(plm_fit5.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit5.1_coef <- coeftest_plm_fit5.1[,c(1)] 
plm_fit5.1_se <- coeftest_plm_fit5.1[,2] 

plm_fit5.2 <- plm(labormarketbills ~  pr, data = bills_extended, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.2 <- coeftest(plm_fit5.2, vcov = plm::vcovHC(plm_fit5.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit5.2_coef <- coeftest_plm_fit5.2[,c(1)]
plm_fit5.2_se <- coeftest_plm_fit5.2[,2] 

plm_fit5.3 <- plm(taxationbills ~  pr, data = bills_extended, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.3 <- coeftest(plm_fit5.3, vcov = plm::vcovHC(plm_fit5.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit5.3_coef <- coeftest_plm_fit5.3[,c(1)] 
plm_fit5.3_se <- coeftest_plm_fit5.3[,2] 

plm_fit5.4 <- plm(pork ~  pr, data = bills_extended, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit5.4 <- coeftest(plm_fit5.4, vcov = plm::vcovHC(plm_fit5.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit5.4_coef <- coeftest_plm_fit5.4[,c(1)] 
plm_fit5.4_se <- coeftest_plm_fit5.4[,2] 


stargazer(plm_fit5.1, plm_fit5.2, plm_fit5.3, plm_fit5.4,
          coef = list(plm_fit5.1_coef, plm_fit5.2_coef, plm_fit5.3_coef, plm_fit5.4_coef),
          se = list(plm_fit5.1_se, plm_fit5.2_se, plm_fit5.3_se, plm_fit5.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))



## Placebo tests (Appendix R)

bills_extended$placebo_treatment1906 <- ifelse(bills_extended$legislativeperiod ==9, 1, 0)

bills_extended$placebo_treatment1910<- ifelse(bills_extended$legislativeperiod ==10, 1, 0)

bills_extended$placebo_treatment1924 <- ifelse(bills_extended$legislativeperiod ==13, 1, 0)

bills19021910 <- subset(bills_extended, legislativeperiod %in% c(8:9))

bills19021910 <- bills19021910 %>%
  group_by(legislatorid) %>%
  filter(n() > 1) %>%
  ungroup()

bills19061914 <- subset(bills_extended, legislativeperiod %in% c(9:10))

bills19061914 <- bills19061914 %>%
  group_by(legislatorid) %>%
  filter(n() > 1) %>%
  ungroup()

bills19191928 <- subset(bills_extended, legislativeperiod %in% c(12:13))

bills19191928 <- bills19191928 %>%
  group_by(legislatorid) %>%
  filter(n() > 1) %>%
  ungroup()

## now placebo treatments in 2-period pairs 


plm_fit5.5 <- plm(socialpolicybills ~  placebo_treatment1906, data = bills19021910, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.5 <- coeftest(plm_fit5.5, vcov = plm::vcovHC(plm_fit5.5, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.6 <- plm(labormarketbills ~  placebo_treatment1906, data = bills19021910, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.6 <- coeftest(plm_fit5.6, vcov = plm::vcovHC(plm_fit5.6, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.7 <- plm(taxationbills ~  placebo_treatment1906, data = bills19021910, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.7 <- coeftest(plm_fit5.7, vcov = plm::vcovHC(plm_fit5.7, method = "arellano", type = "HC1", cluster = "group"))

stargazer(coeftest_plm_fit5.5, coeftest_plm_fit5.6, coeftest_plm_fit5.7, star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001))

plm_fit5.8 <- plm(socialpolicybills ~  placebo_treatment1910, data = bills19061914, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.8 <- coeftest(plm_fit5.8, vcov = plm::vcovHC(plm_fit5.8, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.9 <- plm(labormarketbills ~  placebo_treatment1910, data = bills19061914, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.9 <- coeftest(plm_fit5.9, vcov = plm::vcovHC(plm_fit5.9, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.10 <- plm(taxationbills ~  placebo_treatment1910, data = bills19061914, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.10 <- coeftest(plm_fit5.10, vcov = plm::vcovHC(plm_fit5.10, method = "arellano", type = "HC1", cluster = "group"))

stargazer(coeftest_plm_fit5.8, coeftest_plm_fit5.9, coeftest_plm_fit5.10, star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001))

plm_fit5.11 <- plm(socialpolicybills ~  placebo_treatment1924, data = bills19191928, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.11 <- coeftest(plm_fit5.11, vcov = plm::vcovHC(plm_fit5.11, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.12 <- plm(labormarketbills ~  placebo_treatment1924, data = bills19191928, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.12 <- coeftest(plm_fit5.12, vcov = plm::vcovHC(plm_fit5.12, method = "arellano", type = "HC1", cluster = "group"))

plm_fit5.13 <- plm(taxationbills ~  placebo_treatment1924, data = bills19191928, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit5.13 <- coeftest(plm_fit5.13, vcov = plm::vcovHC(plm_fit5.13, method = "arellano", type = "HC1", cluster = "group"))

stargazer(coeftest_plm_fit5.11, coeftest_plm_fit5.12, coeftest_plm_fit5.13, star.char = c("+", "*", "**", "***"), star.cutoffs = c(.1, .05, .01, .001))


# Analysis: only conservative deputies (Appendix Table M1)

bills_republicanright <- subset(bills, republicanright ==1)

plm_fit6.1 <- plm(socialpolicybills ~ pr, data = bills_republicanright, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.1 <- coeftest(plm_fit6.1, vcov = plm::vcovHC(plm_fit6.1, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.1_coef <- coeftest_plm_fit6.1[,c(1)] 
plm_fit6.1_se <- coeftest_plm_fit6.1[,2] 

plm_fit6.2 <- plm(labormarketbills ~ pr, data = bills_republicanright, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.2 <- coeftest(plm_fit6.2, vcov = plm::vcovHC(plm_fit6.2, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.2_coef <- coeftest_plm_fit6.2[,c(1)] 
plm_fit6.2_se <- coeftest_plm_fit6.2[,2] 

plm_fit6.3 <- plm(taxationbills ~ pr, data = bills_republicanright, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.3 <- coeftest(plm_fit6.3, vcov = plm::vcovHC(plm_fit6.3, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.3_coef <- coeftest_plm_fit6.3[,c(1)] 
plm_fit6.3_se <- coeftest_plm_fit6.3[,2] 

plm_fit6.4 <- plm(pork ~ pr, data = bills_republicanright, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.4 <- coeftest(plm_fit6.4, vcov = plm::vcovHC(plm_fit6.4, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.4_coef <- coeftest_plm_fit6.4[,c(1)] 
plm_fit6.4_se <- coeftest_plm_fit6.4[,2] 

stargazer(plm_fit6.1, plm_fit6.2, plm_fit6.3, plm_fit6.4,
          coef = list(plm_fit6.1_coef, plm_fit6.2_coef, plm_fit6.3_coef, plm_fit6.4_coef),
          se = list(plm_fit6.1_se, plm_fit6.2_se, plm_fit6.3_se, plm_fit6.4_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))

# only radical deputies (Appendix Table M2)

bills_radical <- subset(bills, radical ==1)

plm_fit6.5 <- plm(socialpolicybills ~ pr, data = bills_radical, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.5 <- coeftest(plm_fit6.5, vcov = plm::vcovHC(plm_fit6.5, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.5_coef <- coeftest_plm_fit6.5[,c(1)] 
plm_fit6.5_se <- coeftest_plm_fit6.5[,2] 

plm_fit6.6 <- plm(labormarketbills ~ pr, data = bills_radical, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.6 <- coeftest(plm_fit6.6, vcov = plm::vcovHC(plm_fit6.6, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.6_coef <- coeftest_plm_fit6.6[,c(1)] 
plm_fit6.6_se <- coeftest_plm_fit6.6[,2] 

plm_fit6.7 <- plm(taxationbills ~ pr, data = bills_radical, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.7 <- coeftest(plm_fit6.7, vcov = plm::vcovHC(plm_fit6.7, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.7_coef <- coeftest_plm_fit6.7[,c(1)] 
plm_fit6.7_se <- coeftest_plm_fit6.7[,2] 

plm_fit6.8 <- plm(pork ~ pr, data = bills_radical, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit6.8 <- coeftest(plm_fit6.8, vcov = plm::vcovHC(plm_fit6.8, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.8_coef <- coeftest_plm_fit6.8[,c(1)]
plm_fit6.8_se <- coeftest_plm_fit6.8[,2]


stargazer(plm_fit6.5, plm_fit6.6, plm_fit6.7, plm_fit6.8,
          coef = list(plm_fit6.5_coef, plm_fit6.6_coef, plm_fit6.7_coef, plm_fit6.8_coef),
          se = list(plm_fit6.5_se, plm_fit6.6_se, plm_fit6.7_se, plm_fit6.8_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## only socialist deputies (Appendix Table M3)

bills_socialist <- subset(bills, socialist ==1)

plm_fit6.9 <- plm(socialpolicybills ~ pr, data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.9 <- coeftest(plm_fit6.9, vcov = plm::vcovHC(plm_fit6.9, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.9_coef <- coeftest_plm_fit6.9[,c(1)] 
plm_fit6.9_se <- coeftest_plm_fit6.9[,2] 

plm_fit6.10 <- plm(labormarketbills ~ pr, data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.10 <- coeftest(plm_fit6.10, vcov = plm::vcovHC(plm_fit6.10, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.10_coef <- coeftest_plm_fit6.10[,c(1)] 
plm_fit6.10_se <- coeftest_plm_fit6.10[,2] 

plm_fit6.11 <- plm(taxationbills ~ pr, data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.11 <- coeftest(plm_fit6.11, vcov = plm::vcovHC(plm_fit6.11, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.11_coef <- coeftest_plm_fit6.11[,c(1)] 
plm_fit6.11_se <- coeftest_plm_fit6.11[,2] 

plm_fit6.12 <- plm(pork ~ pr, data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual")
coeftest_plm_fit6.12 <- coeftest(plm_fit6.12, vcov = plm::vcovHC(plm_fit6.12, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.12_coef <- coeftest_plm_fit6.12[,c(1)] 
plm_fit6.12_se <- coeftest_plm_fit6.12[,2] 

stargazer(plm_fit6.9, plm_fit6.10, plm_fit6.11, plm_fit6.12,
          coef = list(plm_fit6.9_coef, plm_fit6.10_coef, plm_fit6.11_coef, plm_fit6.12_coef),
          se = list(plm_fit6.9_se, plm_fit6.10_se, plm_fit6.11_se, plm_fit6.12_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


# socialist deputies only: DM magnitude (Appendix Table N1)

plm_fit6.13 <- plm(socialpolicybills ~ districtmagnitude + I(districtmagnitude^2), data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.13 <- coeftest(plm_fit6.13, vcov = plm::vcovHC(plm_fit6.13, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.13_coef <- coeftest_plm_fit6.13[,c(1)] 
plm_fit6.13_se <- coeftest_plm_fit6.13[,2] 

plm_fit6.14 <- plm(labormarketbills ~ districtmagnitude + I(districtmagnitude^2), data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.14 <- coeftest(plm_fit6.14, vcov = plm::vcovHC(plm_fit6.14, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.14_coef <- coeftest_plm_fit6.14[,c(1)] 
plm_fit6.14_se <- coeftest_plm_fit6.14[,2] 

plm_fit6.15 <- plm(taxationbills ~ districtmagnitude + I(districtmagnitude^2), data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.15 <- coeftest(plm_fit6.15, vcov = plm::vcovHC(plm_fit6.15, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.15_coef <- coeftest_plm_fit6.15[,c(1)]
plm_fit6.15_se <- coeftest_plm_fit6.15[,2] 

plm_fit6.16 <- plm(pork ~ districtmagnitude + I(districtmagnitude^2), data = bills_socialist, index = c("legislatorid","legislativeperiod"), model = "within", effect = "individual") 
coeftest_plm_fit6.16 <- coeftest(plm_fit6.16, vcov = plm::vcovHC(plm_fit6.16, method = "arellano", type = "HC1", cluster = "group"))
plm_fit6.16_coef <- coeftest_plm_fit6.16[,c(1)] 
plm_fit6.16_se <- coeftest_plm_fit6.16[,2] 

stargazer(plm_fit6.13, plm_fit6.14, plm_fit6.15, plm_fit6.16,
          coef = list(plm_fit6.13_coef, plm_fit6.14_coef, plm_fit6.15_coef, plm_fit6.16_coef),
          se = list(plm_fit6.13_se, plm_fit6.14_se, plm_fit6.15_se, plm_fit6.16_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## CANDIDATE BEHAVIOR

# with controls (bottom row of coefficients in Figure 4 of main text; Appendix Table G2)

pfit1 <- plm(cover_unemployment ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit1<- coeftest(pfit1, vcov = plm::vcovHC(pfit1, method = "arellano", type = "HC1", cluster = "group"))
pfit1_coef <- coeftest_pfit1[,c(1)] 
pfit1_se <- coeftest_pfit1[,2] 

pfit2 <- plm(pensions ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit2<- coeftest(pfit2, vcov = plm::vcovHC(pfit2, method = "arellano", type = "HC1", cluster = "group"))
pfit2_coef <- coeftest_pfit2[,c(1)] 
pfit2_se <- coeftest_pfit2[,2] 

pfit3 <- plm(paid_vacation ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit3<- coeftest(pfit3, vcov = plm::vcovHC(pfit3, method = "arellano", type = "HC1", cluster = "group"))
pfit3_coef <- coeftest_pfit3[,c(1)] 
pfit3_se <- coeftest_pfit3[,2] 

pfit4 <- plm(minimum_wage ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit4<- coeftest(pfit4, vcov = plm::vcovHC(pfit4, method = "arellano", type = "HC1", cluster = "group"))
pfit4_coef <- coeftest_pfit4[,c(1)] 
pfit4_se <- coeftest_pfit4[,2] 

pfit5 <- plm(taxhikes ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit5<- coeftest(pfit5, vcov = plm::vcovHC(pfit5, method = "arellano", type = "HC1", cluster = "group"))
pfit5_coef <- coeftest_pfit5[,c(1)] 
pfit5_se <- coeftest_pfit5[,2] 

pfit6 <- plm(five_policy_areas ~ smd + mayor + leader + republicanright + radical + socialist + communist + incomepercapita + pop_eparse + occupied + communist_share, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit6<- coeftest(pfit6, vcov = plm::vcovHC(pfit6, method = "arellano", type = "HC1", cluster = "group"))
pfit6_coef <- coeftest_pfit6[,c(1)] 
pfit6_se <- coeftest_pfit6[,2] 


stargazer(pfit1, pfit2, pfit3, pfit4, pfit5, pfit6,
          coef = list(pfit1_coef, pfit2_coef, pfit3_coef, pfit4_coef, pfit5_coef, pfit6_coef),
          se = list(pfit1_se, pfit2_se, pfit3_se, pfit4_se, pfit5_se, pfit6_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## without controls (top row of coefficients in Table 4 of main text; Appendix Table G1)

pfit7 <- plm(cover_unemployment ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit7 <- coeftest(pfit7, vcov = plm::vcovHC(pfit7, method = "arellano", type = "HC1", cluster = "group"))
pfit7_coef <- coeftest_pfit7[,c(1)] 
pfit7_se <- coeftest_pfit7[,2] 

pfit8 <- plm(pensions ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit8<- coeftest(pfit8, vcov = plm::vcovHC(pfit8, method = "arellano", type = "HC1", cluster = "group"))
pfit8_coef <- coeftest_pfit8[,c(1)]
pfit8_se <- coeftest_pfit8[,2] 

pfit9 <- plm(paid_vacation ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit9 <- coeftest(pfit9, vcov = plm::vcovHC(pfit9, method = "arellano", type = "HC1", cluster = "group"))
pfit9_coef <- coeftest_pfit9[,c(1)] 
pfit9_se <- coeftest_pfit9[,2]

pfit10 <- plm(minimum_wage ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit10 <- coeftest(pfit10, vcov = plm::vcovHC(pfit10, method = "arellano", type = "HC1", cluster = "group"))
pfit10_coef <- coeftest_pfit10[,c(1)]
pfit10_se <- coeftest_pfit10[,2] 

pfit11 <- plm(taxhikes ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit11 <- coeftest(pfit11, vcov = plm::vcovHC(pfit11, method = "arellano", type = "HC1", cluster = "group"))
pfit11_coef <- coeftest_pfit11[,c(1)] 
pfit11_se <- coeftest_pfit11[,2] 

pfit12 <- plm(five_policy_areas ~ smd, data = platforms, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit12 <- coeftest(pfit12, vcov = plm::vcovHC(pfit12, method = "arellano", type = "HC1", cluster = "group"))
pfit12_coef <- coeftest_pfit12[,c(1)] 
pfit12_se <- coeftest_pfit12[,2] 

stargazer(pfit7, pfit8, pfit9, pfit10, pfit11, pfit12,
          coef = list(pfit7_coef, pfit8_coef, pfit9_coef, pfit10_coef, pfit11_coef, pfit12_coef),
          se = list(pfit7_se, pfit8_se, pfit9_se, pfit10_se, pfit11_se, pfit12_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## estimates of platform changes for republican right candidates only (Appendix L)

platforms_republicanright <- subset(platforms, republicanright ==1)

pfit13 <- plm(cover_unemployment ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit13 <- coeftest(pfit13, vcov = plm::vcovHC(pfit13, method = "arellano", type = "HC1", cluster = "group"))
pfit13_coef <- coeftest_pfit13[,c(1)] 
pfit13_se <- coeftest_pfit13[,2] 

pfit14 <- plm(pensions ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit14 <- coeftest(pfit14,  vcov = plm::vcovHC(pfit14, method = "arellano", type = "HC1", cluster = "group"))
pfit14_coef <- coeftest_pfit14[,c(1)] 
pfit14_se <- coeftest_pfit14[,2]

pfit15 <- plm(paid_vacation ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit15 <- coeftest(pfit15,  vcov = plm::vcovHC(pfit15, method = "arellano", type = "HC1", cluster = "group"))
pfit15_coef <- coeftest_pfit15[,c(1)]
pfit15_se <- coeftest_pfit15[,2] 

pfit16 <- plm(minimum_wage ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual") 
coeftest_pfit16 <- coeftest(pfit16,  vcov = plm::vcovHC(pfit16, method = "arellano", type = "HC1", cluster = "group"))
pfit16_coef <- coeftest_pfit16[,c(1)] 
pfit16_se <- coeftest_pfit16[,2] 

pfit17 <- plm(taxhikes ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit17 <- coeftest(pfit17,  vcov = plm::vcovHC(pfit17, method = "arellano", type = "HC1", cluster = "group"))
pfit17_coef <- coeftest_pfit17[,c(1)] 
pfit17_se <- coeftest_pfit17[,2] 

pfit18 <- plm(five_policy_areas ~ smd + mayor + leader + incomepercapita + pop_eparse + occupied + communist_share, data = platforms_republicanright, index = c("legislatorid","year"), model = "within", effect = "individual")
coeftest_pfit18 <- coeftest(pfit18,  vcov = plm::vcovHC(pfit18, method = "arellano", type = "HC1", cluster = "group"))
pfit18_coef <- coeftest_pfit18[,c(1)] 
pfit18_se <- coeftest_pfit18[,2]


stargazer(pfit13, pfit14, pfit15, pfit16, pfit17, pfit18,
          coef = list(pfit13_coef, pfit14_coef, pfit15_coef, pfit16_coef, pfit17_coef, pfit18_coef),
          se = list(pfit13_se, pfit14_se, pfit15_se, pfit16_se, pfit17_se, pfit18_se),
          star.char = c("+", "*", "**", "***"),
          star.cutoffs = c(.1, .05, .01, .001))


## generate Figure 3 in main text 

extract_pr <- function(coeftest_obj, term_label, model_label){
  
  est <- coeftest_obj["pr",1]
  se  <- coeftest_obj["pr",2]
  
  data.frame(
    model = model_label,
    term = term_label,
    estimate = est,
    se = se,
    conf.low = est - 1.96 * se,
    conf.high = est + 1.96 * se
  )
}

pr_regression_results <- rbind(
  
  # 1914–1932 baseline
  extract_pr(coeftest_plm_fit1.4, "Pork bills", "1914-1932 (baseline)"),
  extract_pr(coeftest_plm_fit1.3, "Taxation bills", "1914-1932 (baseline)"),
  extract_pr(coeftest_plm_fit1.2, "Labor market bills", "1914-1932 (baseline)"),
  extract_pr(coeftest_plm_fit1.1, "Social policy bills", "1914-1932 (baseline)"),
  
  # 1914–1932 controls
  extract_pr(coeftest_plm_fit1.8, "Pork bills", "1914-1932 (controls)"),
  extract_pr(coeftest_plm_fit1.7, "Taxation bills", "1914-1932 (controls)"),
  extract_pr(coeftest_plm_fit1.6, "Labor market bills", "1914-1932 (controls)"),
  extract_pr(coeftest_plm_fit1.5, "Social policy bills", "1914-1932 (controls)"),
  
  # 1919–1932 baseline
  extract_pr(coeftest_plm_fit2.4, "Pork bills", "1919-1932 (baseline)"),
  extract_pr(coeftest_plm_fit2.3, "Taxation bills", "1919-1932 (baseline)"),
  extract_pr(coeftest_plm_fit2.2, "Labor market bills", "1919-1932 (baseline)"),
  extract_pr(coeftest_plm_fit2.1, "Social policy bills", "1919-1932 (baseline)"),
  
  # 1919–1932 controls
  extract_pr(coeftest_plm_fit2.4c, "Pork bills", "1919-1932 (controls)"),
  extract_pr(coeftest_plm_fit2.3c, "Taxation bills", "1919-1932 (controls)"),
  extract_pr(coeftest_plm_fit2.2c, "Labor market bills", "1919-1932 (controls)"),
  extract_pr(coeftest_plm_fit2.1c, "Social policy bills", "1919-1932 (controls)")
  
)

pr_regression_results$term <- factor(
  pr_regression_results$term,
  levels = c("Pork bills","Taxation bills","Labor market bills","Social policy bills")
)

pr_regression_results$model <- factor(
  pr_regression_results$model,
  levels = c(
    "1919-1932 (controls)",
    "1919-1932 (baseline)",
    "1914-1932 (controls)",
    "1914-1932 (baseline)"
  )
)

results <- pr_regression_results


pd <- position_dodge(width=0.4)

results <-  results %>%
  arrange(estimate) %>%
  mutate(term = factor(term, levels=c("Pork bills","Taxation bills","Labor market bills","Social policy bills")))

results <-  results %>%
  arrange(estimate) %>%
  mutate(model = factor(model, levels=c("1919-1932 (controls)","1919-1932 (baseline)","1914-1932 (controls)","1914-1932 (baseline)")))

plot1 <- ggplot(results, aes(y=term, x=estimate, shape=model)) +
  geom_point(size=2, position=pd) +
  scale_shape_manual(values = c(0,1,2,5)) +
  geom_hline(yintercept=0) +
  geom_errorbar(aes(color=model, xmin = conf.low, xmax = conf.high),
                width = 0.1, position = pd) +
  theme_bw() +
  geom_vline(xintercept = 0) + 
  scale_color_manual(values=c("#999999","#999999","#000000","#000000"), guide = FALSE) +
  xlim(-1, 1) +
  guides(shape = guide_legend(reverse=TRUE)) +
  ylab("") +
  xlab("Estimate") +
  labs(shape=NULL) +
  theme(text=element_text(size=15))


# Generate figure 4 in main text

extract_smd <- function(coeftest_obj, term_label, model_label){
  
  est <- coeftest_obj["smd",1]
  se  <- coeftest_obj["smd",2]
  
  data.frame(
    model = model_label,
    term = term_label,
    estimate = est,
    se = se,
    conf.low = est - 1.96 * se,
    conf.high = est + 1.96 * se
  )
}

manifesto_results <- rbind(
  
  # baseline models
  extract_smd(coeftest_pfit12, "Five policy average", "baseline"),
  extract_smd(coeftest_pfit11, "Increase top taxes", "baseline"),
  extract_smd(coeftest_pfit10, "Minimum wage", "baseline"),
  extract_smd(coeftest_pfit9, "Paid vacation", "baseline"),
  extract_smd(coeftest_pfit8, "Increase pensions", "baseline"),
  extract_smd(coeftest_pfit7, "Insure unemployment", "baseline"),
  
  # control models
  extract_smd(coeftest_pfit6, "Five policy average", "controls"),
  extract_smd(coeftest_pfit5, "Increase top taxes", "controls"),
  extract_smd(coeftest_pfit4, "Minimum wage", "controls"),
  extract_smd(coeftest_pfit3, "Paid vacation", "controls"),
  extract_smd(coeftest_pfit2, "Increase pensions", "controls"),
  extract_smd(coeftest_pfit1, "Insure unemployment", "controls")
  
)

manifesto_results <- manifesto_results %>%
  mutate(
    term = factor(term, levels = c(
      "Five policy average",
      "Increase top taxes",
      "Minimum wage",
      "Paid vacation",
      "Increase pensions",
      "Insure unemployment"
    )),
    model = factor(model, levels = c("controls","baseline"))
  )

pd <- position_dodge(width = 0.4)

plot2 <- ggplot(manifesto_results, aes(y = term, x = estimate, shape = model)) +
  geom_point(size = 2, position = pd) +
  scale_shape_manual(values = c(2,5)) +
  geom_hline(yintercept = 0) +
  geom_errorbar(aes(xmin = conf.low, xmax = conf.high),
                width = 0.1, position = pd) +
  theme_bw() +
  geom_vline(xintercept = 0) +
  xlim(-0.2, 0.2) +
  guides(shape = guide_legend(reverse = TRUE)) +
  ylab("") +
  xlab("Estimate") +
  labs(shape = NULL) +
  theme(text = element_text(size = 15))

## create barplot with averages per session (figure 2)

summary_socialpolicy <- bills %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(socialpolicybills, na.rm = TRUE))

summary_socialpolicy$variable <- "Social policy bills"

summary_labormarketbills <- bills %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(labormarketbills, na.rm = TRUE))

summary_labormarketbills$variable <- "Labor market bills"

summary_taxationbills <- bills %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(taxationbills, na.rm = TRUE))

summary_taxationbills$variable <- "Taxation bills"

summary_porkbills <- bills %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(pork, na.rm = TRUE))

summary_porkbills$variable <- "Pork bills"

summary_statistics <- rbind(
  summary_socialpolicy,
  summary_labormarketbills,
  summary_taxationbills,
  summary_porkbills
)

summary_statistics$legislativeperiod1 <- NA

summary_statistics$legislativeperiod1[summary_statistics$legislativeperiod == 11] <- "1914-1919"
summary_statistics$legislativeperiod1[summary_statistics$legislativeperiod == 12] <- "1919-1924"
summary_statistics$legislativeperiod1[summary_statistics$legislativeperiod == 13] <- "1924-1928"
summary_statistics$legislativeperiod1[summary_statistics$legislativeperiod == 14] <- "1928-1932"

summary_statistics$variable <- factor(
  summary_statistics$variable,
  levels = c("Social policy bills","Labor market bills","Taxation bills","Pork bills")
)

summary_plot1 <- ggplot(summary_statistics, aes(x = legislativeperiod1, y = mean, fill = variable)) +
  geom_col(position = "dodge") +
  labs(title = "", x = "Legislative Period", y = "Mean bills proposed per legislator ") +
  theme_minimal() +
  scale_fill_grey(start = 0.2, end = 0.8) +
  theme(
    legend.position = "bottom",
    legend.title = element_blank(),
    axis.text.x = element_text(vjust = 4)
  )

## create barplot with averages per session (1902-1932)

summary_socialpolicy <- bills_extended %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(socialpolicybills, na.rm = TRUE))

summary_socialpolicy$variable <- "Social policy bills"

summary_labormarketbills <- bills_extended %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(labormarketbills, na.rm = TRUE))

summary_labormarketbills$variable <- "Labor market bills"

summary_taxationbills <- bills_extended %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(taxationbills, na.rm = TRUE))

summary_taxationbills$variable <- "Taxation bills"

summary_porkbills <- bills_extended %>%
  group_by(legislativeperiod) %>% 
  summarize(mean = mean(pork, na.rm = TRUE))

summary_porkbills$variable <- "Pork bills"

summary_statistics <- rbind(
  summary_socialpolicy,
  summary_labormarketbills,
  summary_taxationbills,
  summary_porkbills
)

summary_statistics$legislativeperiod <- as.numeric(summary_statistics$legislativeperiod)

summary_statistics$variable <- factor(
  summary_statistics$variable,
  levels = c("Social policy bills","Labor market bills","Taxation bills","Pork bills")
)

summary_plot2 <- ggplot(summary_statistics, aes(x = legislativeperiod, y = mean, fill = variable)) +
  geom_col(position = "dodge") +
  labs(title = "", x = "Legislative Period", y = "Mean bills proposed per legislator ") +
  theme_minimal() +
  scale_fill_grey(start = 0.2, end = 0.8) +
  theme(
    legend.position = "bottom",
    legend.title = element_blank(),
    axis.text.x = element_text(vjust = 4)
  ) +
  scale_x_continuous(breaks = 8:14)